<template>
	<div name="changeBankeInfo">
        <van-nav-bar
			title="修改班课信息"
			left-arrow
			left-text="返回"
			fixed
			@click-left="goBack"
		/>
        <bankeInfo ref="bankeInfo" ></bankeInfo>
        <div style="margin: 19px;">
			<van-button round block type="info" @click="putCourse">修改</van-button>
		</div>
	</div>
</template>

<script>
    import bankeInfo from '@/components/bankeInfo.vue';
    import { updateCourse } from '@/api/course.js'
	export default {
		name: 'changeBankeInfo',
		components: {
            bankeInfo
		},
		created() {
			this.detailBankeInfo = JSON.parse(localStorage.getItem('detailBankeInfo'));
		},
		data(){
			return {
				detailBankeInfo: {}
			}
		},
		computed: {
			
		},
		methods: {
			putCourse() {
                const info = {
					title: this.$refs.bankeInfo.title, // 班级名称*
					courseName: this.$refs.bankeInfo.courseName, // 课程名称*
					teacher: this.$refs.bankeInfo.teacher,  // 任课教师
					college: this.$refs.bankeInfo.college, // 学校*
					school: this.$refs.bankeInfo.school, // 学院*
					major: this.$refs.bankeInfo.major, // 专业
					grade: Number(this.$refs.bankeInfo.grade), // 年级*
					semester: this.$refs.bankeInfo.semester, // 学期*
					learnRequire: this.$refs.bankeInfo.learnRequire, // 学习要求
					teachProgress: this.$refs.bankeInfo.teachProgress, // 教学进度
					collegeId: this.$refs.bankeInfo.colCollegeId[this.$refs.bankeInfo.collegeIndex]
				};
				//  ↓↓↓↓   修改课程信息
                updateCourse(this.detailBankeInfo.id, {  
					"organId": info.collegeId,
					"grade": info.grade,
					"name": info.courseName,
					"semester": info.semester,
					"title": info.title
                }).then(res => {
                    console.log(res);
                    if(res.data.code === 0) {
                        let detlBankeInfo = JSON.parse(localStorage.getItem('detailBankeInfo'));
						detlBankeInfo.title = info.title;
                        detlBankeInfo.grade = info.grade;
                        detlBankeInfo.name = info.courseName;
                        detlBankeInfo.semester = info.semester;
						detlBankeInfo.school = info.school;
						detlBankeInfo.major = info.major;
						detlBankeInfo.college = info.college;
                        localStorage.setItem('detailBankeInfo' , JSON.stringify(detlBankeInfo));
                        this.$toast("修改成功");
                        this.$router.push({
							name: 'detailBanke',
							params: {
								tabbarTempValue: 1
							}
						})
                    } else {
                        this.$toast("修改失败");
                    }
                }).catch(err => {
                    console.log(err);
                })
            },
			goBack() {
				this.$router.push({
				name: 'detailBanke',
				params: {
					tabbarTempValue: 1
				}
			})
			}
		}
	}
</script>

<style>
</style>